package calbs.socket.packaging;

import calbs.socket.pojo.resp.RespAbLineListMsg;
import calbs.socket.pojo.resp.RespAbLineMsg;
import calbs.socket.pojo.resp.RespBaseMsg;
import calbs.socket.pojo.resp.RespData;
import calbs.socket.tool.CHexConver;
import calbs.socket.tool.LatLngTool;

import java.util.List;

/**
 * Created by zhangqin on 2017/8/7.
 */
public class AblineRespPackagingImp  implements PackagingI<RespAbLineListMsg>{


    @Override
    public String analysisMsg(RespData<RespAbLineListMsg> respData) {
        RespAbLineListMsg respAbLineListMsg = respData.getBody();
        int abLineID;
        String fieldname;
        String abLineName;
        String alng;
        String alat;
        double aheight;
        String blng;
        String blat;
        double bheight;
        String basex;
        String basey;
        String basez;
        int utcTime;
        int abLineCount = 0;
        List<RespAbLineMsg> abLineMsgs = respAbLineListMsg.getLineMsgs();
        String content = CHexConver.integeroHexString(abLineCount, 2);
        if(abLineMsgs!=null&&abLineMsgs.size()>0) {
            abLineCount = abLineMsgs.size();
            content = CHexConver.integeroHexString(abLineCount, 2);
            for (int i = 0; i < abLineCount; i++) {
                RespAbLineMsg respAbLineMsg = abLineMsgs.get(i);
                content = content + CHexConver.integeroHexString(i + 1, 2);
                abLineID = respAbLineMsg.getAbLineId();
                content = content + CHexConver.integeroHexString(abLineID, 4);
                fieldname = respAbLineMsg.getFieldName();
                content = content + CHexConver.packagingStr(fieldname);
                abLineName = respAbLineMsg.getAbLineName();
                content = content + CHexConver.packagingStr(abLineName);
                alng = respAbLineMsg.getaLng();
                content = content + CHexConver.LongHexString(LatLngTool.parseLatLng(alng), 4);
                alat = respAbLineMsg.getaLat();
                content = content + CHexConver.LongHexString(LatLngTool.parseLatLng(alat), 4);
                aheight = respAbLineMsg.getaHeight();
                content = content + CHexConver.integeroHexString(LatLngTool.parseHeight(aheight), 4);
                blng = respAbLineMsg.getbLng();
                content = content + CHexConver.LongHexString(LatLngTool.parseLatLng(blng), 4);
                blat = respAbLineMsg.getbLat();
                content = content + CHexConver.LongHexString(LatLngTool.parseLatLng(blat), 4);

                bheight = respAbLineMsg.getbHeight();
                content = content + CHexConver.integeroHexString(LatLngTool.parseHeight(bheight), 4);

                basex = respAbLineMsg.getBasex();
                content = content + CHexConver.LongHexString(Long.parseLong(basex), 4);
                basey = respAbLineMsg.getBasey();
                content = content + CHexConver.LongHexString(Long.parseLong(basey), 4);
                basez = respAbLineMsg.getBasez();
                content = content + CHexConver.LongHexString(Long.parseLong(basez), 4);

                utcTime = respAbLineMsg.getUtcTime();
                content = content + CHexConver.integeroHexString(utcTime, 4);
            }
        }
        return PackingUtils.packing(respData.getBody(),content);
    }

    public static void main(String[] args) {
        String s = "10.86\n" +
                "13.97\n" +
                "11.98\n" +
                "12\n" +
                "12\n" +
                "12.81\n" +
                "12.46\n" +
                "13.13\n" +
                "12.49\n" +
                "12.75\n" +
                "14.03\n" +
                "19.32\n" +
                "20.23\n" +
                "20.36\n" +
                "31.44\n" +
                "32.37\n" +
                "31.73\n" +
                "31.73\n" +
                "31.59\n" +
                "32.52\n" +
                "32.55\n" +
                "33.19\n" +
                "36.7\n" +
                "39.98\n" +
                "42.18\n" +
                "44.48\n" +
                "42.08\n" +
                "41.93\n" +
                "42.77\n" +
                "42.52\n" +
                "42.8\n" +
                "47.14\n" +
                "47.23\n"  ;
        String[] split = s.split("\n");
        String ss = "7E7D83004B02778C000A0001000002640006506C6F75676800074C696E654142370736AC1401DA4235000198330736AC1701DA4215000197CFEF34D6821BE7F8DD138AF4495B21E8E70002000002500006506C6F75676800074C696E654142320736AC0D01DA41D90001E6B80736AC1401DA41B60001E6B8EF34D2FC1BE7F7F2138AF4015A0939440003000002510006506C6F75676800066E6F6E6764610736AC1401DA41900001E71C0736AC2601DA3F61000200E4EF34D2FC1BE7F7F2138AF4015A09400A0004000002520006506C6F75676800084C696E65414231320736AC9E01DA3F0E00031CDF0736AC9A01DA3F4200031B4F0000000000000000000000005AC32E2D0005000002530006506C6F75676800074C696E654142330736AC3E01DA3FEE0001E9730736AC3F01DA40160001E7E40000000000000000000000005B0E66A70006000002740006506C6F75676800074C696E654142310736ABFC01DA42F90001A8370736ABF801DA42CF000221B4EF34D3E81BE7F6D8138AF53B5B29F89D0007000002540006506C6F75676800074C696E654142340736ABE601DA428A00018F380736ABFB01DA425C000190000000000000000000000000005B0E6A080008000002550006506C6F75676800074C696E654142350736ABFB01DA425C000190000736AC0301DA4230000192580000000000000000000000005B0E6ABF0009000002750006506C6F756768000666656E6731310736AC0901DA42360002227C0736AC0E01DA41F90002240BEF34D3E81BE7F6D8138AF53B5B2A0F5C000A000002560006506C6F75676800074C696E654142360736AC0301DA422F000190000736AC0A01DA4208000191F3EF34B8651BE818C4138AB5B35B0E6C087E7D";
        for (String s1 : split) {
            try {
                String s2 = CHexConver.integeroHexString(LatLngTool.parseHeight(new Double(s1)), 4).toUpperCase();
                System.out.println(s2);
                int i = ss.indexOf(s2);
                if(i>-1) {
                    System.out.println(s1);
                }
            }catch (Exception e){

            }
//7E7D83002302778C000A0001000002640006506C6F75676800074C696E654142370736AC1401DA4235000198330736AC1701DA4215000197CFEF34D6821BE7F8DD138AF4495B21E8E70002000002500006506C6F75676800074C696E654142320736AC0D01DA41D90001E6B80736AC1401DA41B60001E6B8EF34D2FC1BE7F7F2138AF4015A0939440003000002510006506C6F75676800066E6F6E6764610736AC1401DA41900001E71C0736AC2601DA3F61000200E4EF34D2FC1BE7F7F2138AF4015A09400A0004000002520006506C6F75676800084C696E65414231320736AC9E01DA3F0E00031CDF0736AC9A01DA3F4200031B4F0000000000000000000000005AC32E2D0005000002530006506C6F75676800074C696E654142330736AC3E01DA3FEE0001E9730736AC3F01DA40160001E7E40000000000000000000000005B0E66A70006000002740006506C6F75676800074C696E654142310736ABFC01DA42F90001A8370736ABF801DA42CF000221B4EF34D3E81BE7F6D8138AF53B5B29F89D0007000002540006506C6F75676800074C696E654142340736ABE601DA428A00018F380736ABFB01DA425C000190000000000000000000000000005B0E6A080008000002550006506C6F75676800074C696E654142350736ABFB01DA425C000190000736AC0301DA4230000192580000000000000000000000005B0E6ABF0009000002750006506C6F756768000666656E6731310736AC0901DA42360002227C0736AC0E01DA41F90002240BEF34D3E81BE7F6D8138AF53B5B2A0F5C000A000002560006506C6F75676800074C696E654142360736AC0301DA422F000190000736AC0A01DA4208000191F3EF34B8651BE818C4138AB5B35B0E6C087E7D
//7E7D83000302779B000A0001000002640006506C6F75676800074C696E654142370736AC1401DA42353E4948300736AC1701DA4215000197CFEF34D6821BE7F8DD138AF4495B21E8E70002000002500006506C6F75676800074C696E654142320736AC0D01DA41D94A4473800736AC1401DA41B60001E6B8EF34D2FC1BE7F7F2138AF4015A0939440003000002510006506C6F75676800066E6F6E6764610736AC1401DA41904A53B5C00736AC2601DA3F61000200E4EF34D2FC1BE7F7F2138AF4015A09400A0004000002520006506C6F75676800084C696E65414231320736AC9E01DA3F0E7997C6F00736AC9A01DA3F4200031B4F0000000000000000000000005AC32E2D0005000002530006506C6F75676800074C696E654142330736AC3E01DA3FEE4AAF1C300736AC3F01DA40160001E7E40000000000000000000000005B0E66A70006000002740006506C6F75676800074C696E654142310736ABFC01DA42F940BAE4700736ABF801DA42CF000221B4EF34D3E81BE7F6D8138AF53B5B29F89D0007000002540006506C6F75676800074C696E654142340736ABE601DA428A3CEA7B800736ABFB01DA425C000190000000000000000000000000005B0E6A080008000002550006506C6F75676800074C696E654142350736ABFB01DA425C3D0900000736AC0301DA4230000192580000000000000000000000005B0E6ABF0009000002750006506C6F756768000666656E6731310736AC0901DA423653630BC00736AC0E01DA41F90002240BEF34D3E81BE7F6D8138AF53B5B2A0F5C000A000002560006506C6F75676800074C696E654142360736AC0301DA422F3D0900000736AC0A01DA4208000191F3EF34B8651BE818C4138AB5B35B0E6C087E7D
        }
    }
}
